/**
 * 判断指定名称的复选框是否被选中
 * @param name
 * @returns {Boolean}
 */
function getCheckedByName(name) {
	var obj = $("[name='" + name + "']");
	var ischeck = false;
	for (var i = 0; i < obj.length; i ++) {
		if (obj[i].checked == true) {
			ischeck = true;
			break;
		}
	}
	return ischeck;
} 

/**
 * 获取指定名称的复选框被选中个数
 * @param name
 * @returns {Number}
 */
function getCheckedNumByName(name) {
	var obj = $("[name='" + name + "']");
	var count = 0;
	for (var i = 0; i < obj.length; i ++) {
		if (obj[i].checked == true) {
			count ++;
		}
	}
	return count;
}

/**
 * 获取指定名称的复选框，单个被选中的值
 * @param name
 * @returns {String}
 */
function getCheckedValueByName(name) {
	var str = "";
	$("input[type='checkbox'][name='" + name + "']:checked").each(function() {
		str += $(this).val();		
	});
	return str;
}

/**
 * 获取多个复选框选中的值
 * @param name
 * @returns {String}
 */
function getCheckedValuesByName(name) {
	var str = "";
	$("input[type='checkbox'][name='" + name + "']:checked").each(function() {
		str += $(this).val() + ",";
	});
	return str.substrin(0, str.length - 1);
}

/**
 * 统一Alert
 * @param msg
 */
function defaultAlert(msg) {
	bootbox.alert({  
		message: "<span class='bigger-110'>" + msg + "</span>",
        buttons: {  
           ok: {  
                label: '<i class=\"icon-off bigger-110\"></i>关闭',  
                className: 'btn-sm'  
            }  
        }
    });  
}

/**
 * 统一Dialog
 * @param msg
 */
function defaultDialog(msg) {
	bootbox.dialog({
		message: "<span class='bigger-110'>" + msg + "</span>",
		buttons: {
			"button" : {
				"label" : "<i class=\"icon-off bigger-110\"></i>关闭",
				"className" : "btn-sm"
			}
		}
	});
}

/**
 * 统一confirm
 * @param msg
 * @param func
 */
function defaultConfirm(msg, func) {
	bootbox.confirm({
		message: "<span class='bigger-110'>" + msg + "</span>", 
		buttons: {
          confirm: {
             label: "<i class=\"icon-ok bigger-110\"></i>确认",
             className: "btn-primary btn-sm"
          },
          cancel: {
             label: "<i class=\"icon-off bigger-110\"></i>取消",
             className: "btn-sm"
          }
        },
        callback: func
	});
}

function isEmpty(msg) {
	return $.trim(msg) == "";	
}

function loading() {
	layer.load(2, {
	  shade: [0.1,'#fff']
	});
}

/**
 * 检查是否为正整数
 */
function checkInt(mum) {
    var regex = /^[0-9]*[1-9][0-9]*$/g;
    return regex.test(mum);
}

/**
 * 验证是否为电话号码（座机）
 *
 * @param {}
 *            source
 */
function isTelephone(source) {
	var regex = /^(0[0-9]{2,3}\-)?([2-9][0-9]{6,7})+(\-[0-9]{1,4})?$/
	return regex.test(source);  //search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1
}

/**
 * 验证是否为手机号码（移动手机）
 *
 * @param {}
 *            source
 */
function isMobilePhone(source) {
	var regex = /^((\(\d{3}\))|(\d{3}\-))?1\d{10}/;
	return regex.test(source);
}

/**
 * 验证电话或手机
 * @param input 需要验证的字符串
 * @return
 */
function validTel(input) {
	return input.search("^(((0\\d{2,3}\\-)?[1-9]{1}\\d{6,7}(\\-\\d{1,4})?)|(1\\d{10}))$");		
}

/**
 * 邮箱验证
 * @param input 需要验证的字符串
 * @return
 */
function validEmail(input) {
	return input.search("^([a-z0-9]([a-z0-9]*[-_]?[a-z0-9]+)*@([a-z0-9]*[-_]?[a-z0-9]+)+[\\.][a-z]{2,3}([\\.][a-z]{2})?)$");		
}



